package cate.game.play.buff.h;

import cate.common.table.d.GDAttr;
import cate.common.table.d.GDSkill;
import cate.common.util.XT;
import cate.game.play.base.TargetFilterParam;
import cate.game.play.base.TargetSelector;
import cate.game.play.buff.BuffHandler;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;

import java.util.List;

/**
 * 攻击时，为我方生命百分比最低的单位回复本次伤害量的20%生命值，持续3回合
 */
public class 莲心BH extends BuffHandler {

	private double 系数;

	//系数=2000
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		系数 = args.getWDouble("系数", 0d);
	}

	@Override
	public void afterOneAttack(SkillActionCtx action, byte nature, long totalDamage, boolean strike, Fighter target) {
		TargetFilterParam filterParam = new TargetFilterParam();
		filterParam.scopeSet(GDSkill.Scope.WE).smallAttrSet(GDAttr.V_HP_LEFT_RATE);
		List<Fighter> fighters = TargetSelector.doFind(buff.owner, action.getTeamVs(), filterParam);
		if(XT.isNotBlank(fighters)){
			fighters.get(0).attr.buffHeal(action, buff.owner, totalDamage*系数);
		}
	}
}
